import 'package:flutter/material.dart';
import 'package:flutter_fitness/component/bottom_bar.dart';
import 'package:flutter_fitness/pages/add_record/add_record_view.dart';
import 'package:flutter_fitness/pages/home/home_view.dart';
import 'package:flutter_fitness/pages/setting/setting_view.dart';
import 'package:get/get.dart';

import 'main_logic.dart';

class MainPage extends StatelessWidget {
  final MainLogic logic = Get.put(MainLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Padding(
          padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
          child: PageView(
            controller: logic.pageController,
            children: [HomePage(), AddRecordPage(), SettingPage()],
            onPageChanged: (index) => logic.index.value = index,
          ),
        ),
        bottomNavigationBar: Obx(() => BottomBar(
            index: logic.index.value,
            onItemPress: (int index) {
              logic.index.value = index;
              logic.pageController.animateToPage(index,
                  duration: Duration(milliseconds: 400), curve: Curves.easeIn);
            })));
  }
}
